<template>
    <div class="box">
        <headers title="分类"></headers>
        <van-row style="flex: 1;overflow: hidden;">
            <van-col span="6" style="height: 100%; overflow: auto;">
                <van-sidebar v-model="active">
                    <van-sidebar-item v-for="(v, i) in list" :key="i" :title="v.cat_name" />
                </van-sidebar>

            </van-col>
            <van-col span="18" style="height: 100%; overflow: auto;">
                <div v-for="(v, i) in list[active]?.children" :key="i">
                    {{ v.cat_name }}
                    <van-grid :border="false" :column-num="2">
                        <van-grid-item v-for="(val, index) in v.children" :key="index" @click="tosearch(val.cat_name)">
                            <van-image :src="val.cat_icon" />
                            {{ val.cat_name }}
                        </van-grid-item>
                    </van-grid>

                </div>
            </van-col>
        </van-row>

    </div>
</template>

<script setup>
import { ref } from "vue";
import { swiperdataApi, catitemsApi, categoriesApi, searchApi, detailApi } from "@/api/api";
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()

import headers from '@/components/headers.vue';

const active = ref(1);

let list = ref('');
const getcategoriesApi = () => {
    categoriesApi().then((res) => {
        list.value = res.data.message
    })
}
getcategoriesApi();

const tosearch = (name) => {
    router.push({ path: '/search', query: { name: name } })
}


</script>

<style lang="scss" scoped>
.box {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}
</style>